/**
 * 
 */
package il.ac.bgu.cs.heuristics.integration;

import java.util.Comparator;

import javaff.planning.FFState;
import javaff.planning.NullFilter;
import javaff.search.BestFirstSearch;

/**
 * An adapter from {@link BestFirstSearch} to {@link ISearchAlgorithm}
 * 
 * @author Ronen Pinko
 * 
 */
public class BestFirstSearchAdapter implements ISearchAlgorithm<FFState>,
		INodeCounter {

	private final Comparator<FFState>	comparator;
	private int							lastSearchNodeCount;

	public BestFirstSearchAdapter(Comparator<FFState> comparator) {
		this.comparator = comparator;
	}

	@Override
	public FFState search(FFState state) {
		// return new BestFirstSearch(state, NullFilter.getInstance(),
		// comparator)
		// .search();

		BestFirstSearch bestFirstSearch = new BestFirstSearch(state, NullFilter
				.getInstance(), comparator);
		FFState goalState = bestFirstSearch.search();
		lastSearchNodeCount = bestFirstSearch.getNodeCount();
		return goalState;
	}

	@Override
	public int getNodeCount() {
		// TODO Auto-generated method stub
		return lastSearchNodeCount;
	}

}
